namespace CSharpPro
{
    using System.Collections.Generic;

    public class UserServiceImpl : UserService
    {
        private Dictionary<string, string> _userDict = new Dictionary<string, string>();

        public void AddUser(string username)
        {
            if (!_userDict.ContainsKey(username))
            {
                _userDict.Add(username, "用户信息");
                Console.WriteLine($"新增用户 {username} 成功");
            }
            else
            {
                Console.WriteLine($"用户 {username} 已存在");
            }
        }

        public void DeleteUser(string username)
        {
            if (_userDict.Remove(username))
            {
                Console.WriteLine($"删除用户 {username} 成功");
            }
            else
            {
                Console.WriteLine($"用户 {username} 不存在");
            }
        }

        public void UpdateUser(string oldUsername, string newUsername)
        {
            if (_userDict.ContainsKey(oldUsername))
            {
                string info = _userDict[oldUsername];
                _userDict.Remove(oldUsername);
                _userDict.Add(newUsername, info);
                Console.WriteLine($"修改用户 {oldUsername} 为 {newUsername} 成功");
            }
            else
            {
                Console.WriteLine($"原用户 {oldUsername} 不存在");
            }
        }

        public void QueryUser(string username)
        {
            if (_userDict.TryGetValue(username, out string info))
            {
                Console.WriteLine($"查询用户 {username}，信息：{info}");
            }
            else
            {
                Console.WriteLine($"用户 {username} 不存在");
            }
        }
    }
}